<?php
namespace Core;
class Base {

    static $_ins = [];

    protected final function __construct()
    {

    }


    function init() {

    }

    function free() {

    }

    /**
     * @param $attr
     * @return static
     */
    static final function Instance(array $attr = []) {
        $className = get_called_class();
        if(!isset(self::$_ins[$className])) {
            self::$_ins[$className] = new static();
        }
        foreach ($attr as $k=>$v) {
            self::$_ins[$className]->$k = $v;
        }
        self::$_ins[$className]->init();
        return self::$_ins[$className];
    }

    static final function FreeObj() {
        foreach (self::$_ins as $k=>$v) {
            $v->free();
        }
    }
}